package com.ruoyi.project.bill.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.project.bill.domain.BillAction;
import com.ruoyi.project.bill.mapper.BillActionMapper;
import com.ruoyi.project.bill.mapper.BillListenerMapper;
import com.ruoyi.project.bill.service.IBillActionService;
import lombok.extern.slf4j.Slf4j;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 单据动作Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@Service
@Slf4j
public class BillActionServiceImpl extends ServiceImpl<BillActionMapper, BillAction> implements IBillActionService
{
    @Autowired
    private BillActionMapper billActionMapper;
    @Autowired
    private BillListenerMapper billListenerMapper;

    /**
     * 查询单据动作
     * 
     * @param id 单据动作主键
     * @return 单据动作
     */
    @Override
    public BillAction selectBillActionById(String id)
    {
        return billActionMapper.selectBillActionById(id);
    }

    /**
     * 批量查询ids
     */
    @Override
    public List<BillAction> selectBillActionByIds(String[] ids)
    {
        return billActionMapper.selectBillActionByIds(ids);
    }

    /**
     * 查询单据动作列表
     * 
     * @param billAction 单据动作
     * @return 单据动作
     */
    @Override
    public List<BillAction> selectBillActionList(BillAction billAction)
    {
        return billActionMapper.selectBillActionList(billAction);
    }

    /**
     * 新增单据动作
     * 
     * @param billAction 单据动作
     * @return 结果
     */
    @Override
    public String insertBillAction(BillAction billAction)
    {
        int code1= billActionMapper.insert(billAction);
        return code1>0? null:"保存失败";
    }

    /**
     * 修改单据动作
     * 
     * @param billAction 单据动作
     * @return 结果
     */
    @Override
    public String updateBillAction(BillAction billAction)
    {
        int code1= billActionMapper.updateById(billAction);
        return code1>0? null:"保存失败";
    }

    /**
     * 批量删除单据动作
     * 
     * @param ids 需要删除的单据动作主键
     * @return 结果
     */
    @Override
    public String deleteBillActionByIds(String[] ids)
    {
        int code = billActionMapper.deleteBatchIds(Collections.arrayToList(ids));
        return code>0?null:"删除失败";
    }

    /**
     * 删除单据动作信息
     * 
     * @param id 单据动作主键
     * @return 结果
     */
    @Override
    public String deleteBillActionById(String id)
    {
        int code= billActionMapper.deleteById(id);
        return code>0?null:"删除失败";
    }


    @Override
    public List<BillAction> getBillActionByBillDefineId(String billDefineId){

        List<BillAction> billActions =  billActionMapper.getBillActionByBillDefineId(billDefineId);

        for(BillAction billAction :billActions){

            billAction.setActionLinseners(billListenerMapper.getBillListenerByActionId(billAction.getId()));
        }
        return billActions;
    }
}
